//
//  MainViewController.m
//  Weiweiyunshi
//
//  Created by 王译 on 17/1/22.
//  Copyright © 2017年 王译. All rights reserved.
//

#import "MainViewController.h"
#import "LBTabBar.h"
#import "VVNavigationController.h"
#import "LoginModel.h"
#import "BusinessViewController.h"
#import "URLViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController

+ (void)initialize
{
    //    UITabBarItem *tabBarItem = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    
    //     UITabBarItem *tabBarItem = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];
    UITabBarItem *tabBarItem = [[UITabBarItem alloc]init];
    
    NSMutableDictionary *dictNormal = [NSMutableDictionary dictionary];
    dictNormal[NSForegroundColorAttributeName] = [UIColor grayColor];
    dictNormal[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    NSMutableDictionary *dictSelected = [NSMutableDictionary dictionary];
    dictSelected[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    dictSelected[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    [tabBarItem setTitleTextAttributes:dictNormal forState:UIControlStateNormal];
    [tabBarItem setTitleTextAttributes:dictSelected forState:UIControlStateSelected];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildViewControllers];
    LBTabBar *tabbar = [[LBTabBar alloc] init];
    tabbar.myDelegate = self;
//    kvc实质是修改了系统的_tabBar
    [self setValue:tabbar forKeyPath:@"tabBar"];
    
//    [[UITabBar appearance] setShadowImage:[UIImage new]];
//    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
//    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
}

-(void)addChildViewControllers
{
    NSArray *array=@[
//                     @{@"clsName":@"UIViewController",@"title":@"会议列表",@"imageName":@"meetinglist"},
//                     @{@"clsName":@"UIViewController",@"title":@"会议室",@"imageName":@"meetingroom"},
                     
                     @{@"clsName":@"AddressViewController",@"title":@"通讯录",@"imageName":@"addresslist"},
//                      @{@"clsName":@"BusinessViewController",@"title":@"业务",@"imageName":@"meetingroom"},
                     
                     @{@"clsName":@"MineViewController",@"title":@"我的",@"imageName":@"my"},
                     ];
    // 遍历数组,添加子控制器
    for (NSDictionary *dict in array) {
        // 通过字典创建对应的控制器
        UIViewController *vc = [self viewControllerWithDict:dict];
        [self addChildViewController:vc];
    }
    
}

-(UIViewController*)viewControllerWithDict:(NSDictionary*)dict {
    
    // 1. 初始化控制器
    UIViewController *vc = [NSClassFromString(dict[@"clsName"]) new];
    // 2. 设置标题 = 导航栏标题+tabbar的标题
    vc.title = dict[@"title"];
    // 3. 设置不同状态下显示的图片
    vc.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"tabbar-%@-normal", dict[@"imageName"]]];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"tabbar-%@-select", dict[@"imageName"]]];
    
    // 使用导航控制器包裹该控制器并返回
    return [[VVNavigationController alloc] initWithRootViewController:vc];
    
}

- (void)tabBarPlusBtnClick:(LBTabBar *)tabBar
{
    
    
    BusinessViewController *plusVC = [[BusinessViewController alloc] init];
    //    plusVC.view.backgroundColor = [self randomColor];
    
    VVNavigationController *navVc = [[VVNavigationController alloc] initWithRootViewController:plusVC];
    
    [self presentViewController:navVc animated:YES completion:nil];
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
